package GUI;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import Listeners.EditPaperListener;
import Listeners.RemovePaperListener;
import Model.Conference;
import Model.Paper;
import Model.User;

/**
 * Class used for constructing JPanels containing
 * important paper information and buttons for
 * editing or removing the paper.
 * 
 * @author Paul Schultz (ps87@uw.edu)
 * @version 11/30/2012
 */
@SuppressWarnings("serial")
public class PaperPanel extends JPanel
{
 
  /**
   * Constructs a new PaperPanel showing a paper's information.
   * 
   * @param the_paper the Paper to be represented in the panel.
   * @param the_conf the Conference the Paper belongs to.
   * @param the_user the User(Author) accessing the tool.
   * @param the_frame Reference to master frame of the application.
   */
  public PaperPanel(final Paper the_paper, final Conference the_conf, 
      final User the_user, final ConferenceWizardFrame the_frame)
  {
    super();
    this.setAlignmentX(LEFT_ALIGNMENT);
    GridLayout gLayout = new GridLayout(0,2);
    //gLayout.setHgap(80);
    this.setLayout(gLayout);
    JLabel titleLabel = new JLabel("Title: " + the_paper.getTitle());
    titleLabel.setFont(new Font("Plain", Font.PLAIN, 18));
    titleLabel.setAlignmentX(LEFT_ALIGNMENT);
    
    JLabel authorLabel = new JLabel("Author: " + the_paper.getAuthor().realName());
    authorLabel.setFont(new Font("Plain", Font.PLAIN, 16));
    authorLabel.setForeground(new Color(0, 0, 102));
    
    JPanel button_panel = new JPanel();
    JButton editPaper = new JButton("Edit Paper");
    editPaper.addActionListener(new EditPaperListener(the_conf, the_frame, the_user, the_paper));
    button_panel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    
    JLabel spacer = new JLabel("");
    spacer.setFont(new Font("Plain", Font.PLAIN, 16));
   
    button_panel.add(spacer);
    button_panel.add(editPaper);
    
    JPanel button_panel2 = new JPanel();
    JButton removePaper = new JButton("Remove Paper");
    removePaper.addActionListener(new RemovePaperListener(the_conf, the_paper, the_user, the_frame));
    
    button_panel2.setLayout(new FlowLayout(FlowLayout.TRAILING));
    button_panel2.add(removePaper);

    this.add(titleLabel);
    this.add(button_panel);
    this.add(authorLabel);
    this.add(button_panel2);
    
    //this.setPreferredSize();
    this.setMaximumSize(new Dimension(750, 80));
    this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
    
  }
}
